package bg.uni_sofia.conf_manager.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;


import org.eclipse.persistence.oxm.annotations.XmlInverseReference;


@Entity
@NamedQueries({
		@NamedQuery(name = "getAllCompanies", query = "SELECT c FROM Company c"),
		@NamedQuery(name = "getCompanyById", query = "SELECT c FROM Company c WHERE c.id = :id"),
		@NamedQuery(name = "getCompanyByName", query = "SELECT c FROM Company c WHERE c.companyName = :companyName"),
		@NamedQuery(name = "updateCompanyisActiveById", query = "UPDATE Company c SET c.isActive = :isActive "
				+ "WHERE c.id = :id") })
@XmlRootElement
public class Company implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8719740309678607242L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	@Column(name = "companyName")
	private String companyName;
	private String information;
	@Column(name = "isActive")
	private boolean isActive;
	@OneToMany
	@XmlInverseReference(mappedBy = "company")
	private List<Employee> employees;

	public Company() {

	}

	

	public long getId() {
		return id;
	}


	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getInformation() {
		return information;
	}

	public void setInformation(String information) {
		this.information = information;
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public List<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(List<Employee> emmployees) {
		this.employees = emmployees;
	}

	public void addEmployee(Employee employee){
		if(employee!=null){
			getEmployees().add(employee);
		}
	}


	public Company(String companyName, String information, boolean isActive,
			List<Employee> employees) {
		super();
		this.companyName = companyName;
		this.information = information;
		this.isActive = isActive;
		this.employees = employees;
		this.isActive = true;
	}

	
	
}
